package schema

import (
	"entgo.io/ent"
	"entgo.io/ent/schema/edge"
	"entgo.io/ent/schema/field"
	"time"
)

// Countdown holds the schema definition for the Countdown entity.
type Countdown struct {
	ent.Schema
}

// Fields of the Countdown.
func (Countdown) Fields() []ent.Field {
	return []ent.Field{
		field.String("title").
			NotEmpty().
			Comment("标题"),
		field.Time("target_date").
			Comment("目标日期"),
		field.Text("description").
			Optional().
			Comment("描述"),
		field.String("type").
			Default("其他").
			Comment("类型：见面/纪念日/其他"),
		field.Int64("creator_id").
			Comment("创建者ID"),
		field.Time("created_at").
			Default(time.Now).
			Immutable().
			Comment("创建时间"),
		field.Time("updated_at").
			Default(time.Now).
			UpdateDefault(time.Now).
			Comment("更新时间"),
	}
}

// Edges of the Countdown.
func (Countdown) Edges() []ent.Edge {
	return []ent.Edge{
		edge.From("creator", User.Type).
			Ref("countdowns").
			Field("creator_id").
			Unique().
			Required(),
	}
}
